<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ include file="../common/taglibs.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <LINK rel="Bookmark" href="/favicon.ico" >
    <LINK rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <script type="text/javascript" src="lib/PIE_IE678.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.7/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="lib/icheck/icheck.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>全局黑名单</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 全局黑名单 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <form class="form form-horizontal" >
        <div  class="cl pd-5 bg-1 bk-gray mt-20">添加黑名单</div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-1"><span class="c-red">*</span>地址：</label>
            <div class="formControls col-xs-8 col-sm-5">
                <input type="text" class="input-text" autocomplete="off" value="" id="address" name="address">
            </div>
            <div class="col-xs-2 co-sm-2">
                <a href="javascript:addBlack();" class="btn btn-primary radius">添加</a>
            </div>
        </div>
        <div class="row">
            注：当对象为邮箱时请在“地址”里填写邮件地址，对象为域时请在“地址”中填写“@域名”，如“@test.com”。
        </div>
    </form>
    <table class="table table-border table-bordered table-bg">
        <thead>
        <tr class="text-c">
            <th width="25"><input type="checkbox" name="ids" value=""></th>
            <th width="40">序号</th>
            <th width="100">地址</th>
            <th width="150">添加时间</th>
            <th width="90">状态</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${list}" var="item" varStatus="index" >
            <tr width="25">
                <td align="center"><input type="checkbox" _data="${item.address}"  name="id" value="${item.id}"></td>
                <td>${index.index+1}</td>
                <td>${item.address}</td>
                <td>${item.dataTime}</td>
                <td align="center">
                    ${item.status==1?'正常':"禁用"}
                </td>

            </tr>

        </c:forEach>

        </tbody>
    </table>
    <div  class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a href="javascript:;" onclick="deleteB()" class="btn btn-danger radius">
                <i class="Hui-iconfont"></i> 删除所选项</a>
            <a href="javascript:;" onclick="updateB(0)" class="btn btn-danger radius">
                <i class="Hui-iconfont"></i> 禁用所选项</a>
            <a href="javascript:;" onclick="updateB(1)" class="btn btn-primary radius">
                <i class="Hui-iconfont"></i> 启用所选项</a>
        </span>
    </div>
</div>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="lib/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript">
    $(function(){

    });

    function addBlack() {
        var address = $.trim($("#address").val());
        $.ajax({
            url:"${pageContext.request.contextPath}/addBlackList.htmlx",
            data:{
                "address":address
            },
            dataType:'text',
            success:function (data) {
                if(data=="error"){
                    layer.msg("请勿重复添加",{icon:5});
                    location.reload();
                }else if(data=="reman"){
                    layer.confirm("已存在在白名单中,是否删除白名单后继续?",{
                        btn:["确定","取消"]
                    },function () {
                        deleteWa();
                    });
                }else {
                    layer.msg("添加成功",{icon:1});
                    location.reload();

                }

            }
        });
    }
    function deleteB() {
        var a = $("input[name=id]:checked");
        var arr =[];
        $.each(a,function (i) {
            var b = $(a[i]).val();
            if(b){
               arr.push(b);
            }
        });
        if(arr.length==0){
            layer.msg("您还没有选中",{icon:5});
            return;
        }
        $.ajax({
            url:"${pageContext.request.contextPath}/deleteBlackList.htmlx",
            data:{
                ids:arr.join(",")
            },
            dataType:'text',
            success:function(data){
                layer.msg("操作成功",{icon:1});
                location.reload();
            }
        });
    }

    function deleteWa() {
        var a = $("#address").val();
        $.ajax({
            url:"${pageContext.request.contextPath}/deleteWhiteListByAddress.htmlx",
            data:{
                address:a
            },
            dataType:'text',
            success:function(data){
                addBlack();
            }
        });
    }
    function updateB(f) {
        var a = $("input[name=id]:checked");
        var arr =[];
        $.each(a,function (i) {
            var b = $(a[i]).val();
            if(b){
                arr.push(b);
            }
        });
        if(arr.length==0){
            layer.msg("您还没有选中",{icon:5});
            return;
        }
        $.ajax({
            url:"${pageContext.request.contextPath}/upateBlackList.htmlx",
            data:{
                ids:arr.join(","),
                flag:f
            },
            dataType:'text',
            success:function(data){
                layer.msg("操作成功",{icon:1});
                location.reload();
            }
        });
    }
    /*
     参数解释：
     title   标题
     url     请求的url
     id      需要操作的数据id
     w       弹出层宽度（缺省调默认值）
     h       弹出层高度（缺省调默认值）
     */
    /*管理员-增加*/
    function admin_add(title,url,w,h){
        url=url
        layer_show(title,url,w,h);
    }
    /*管理员-删除*/
    function admin_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                url: "deleteStore.htmlx",
                type:"POST",
                data:{ids:id},
                success: function(data){
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                },
                error: function(data){
                    layer.msg('操作失败!请联系系统管理员!',{icon: 5,time:1000});
                }
            })
        });
    }
    /*编辑*/
    function admin_edit(title,url,id,w,h){
        url=url+"?id="+id;
        layer_show(title,url,w,h);
    }
    /*停用*/
    function admin_stop(obj,id){
        layer.confirm('确认要停用吗？',function(index){
            $.ajax({
                url: "stopStore.htmlx",
                type:"POST",
                data:{id:id},
                success: function(data){
                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_start(this,id)" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe6e1;</i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
                    $(obj).remove();
                    layer.msg('已停用!',{icon: 5,time:1000});
                },
                error: function(data){
                    layer.msg('操作失败!请联系系统管理员!',{icon: 5,time:1000});
                }
            })
        });
    }

    /*启用*/
    function admin_start(obj,id){
        layer.confirm('确认要启用吗？',function(index){
            $.ajax({
                url: "startStore.htmlx",
                type:"POST",
                data:{id:id},
                success: function(data){
                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_stop(this,id)" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
                    $(obj).remove();
                    layer.msg('已启用!',{icon: 6,time:1000});
                },
                error: function(data){
                    layer.msg('操作失败!请联系系统管理员!',{icon: 5,time:1000});
                }
            })

        });
    }
</script>
</body>
</html>